package com.example.combwx.mvp.base.view;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.BarUtils;
import com.example.combwx.mvp.base.presenter.IPresenter;
import com.example.combwx.utils.ToasetUtils;
import com.umeng.analytics.MobclickAgent;
import javax.inject.Inject;

public abstract class BaseActivity<P extends IPresenter>
        extends AppCompatActivity implements IView,IActivity {

    @Inject
    public P p;

    @SuppressLint("ResourceAsColor")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(bindLayout());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            //把状态栏标记为浅色，然后状态栏的字体颜色自动转换为深色
        }
        BarUtils.setStatusBarColor(this, addcolor());
        //添加让出状态栏高度->防止contentView布局绘制到状态栏上
        BarUtils.addMarginTopEqualStatusBarHeight(addStatusView());
        initView();
        inject();
        getLifecycle().addObserver(p);
        initData();
    }

    public abstract View addStatusView();
    public abstract int addcolor();

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        getLifecycle().removeObserver(p);
    }

    @Override
    public void showDialog() {

    }

    @Override
    public void hideDialog() {

    }

    @Override
    public void showMsg(String msg) {
        ToasetUtils.showMsg(msg);
    }

    @Override
    public void startPage(Bundle bundle,Class clazz) {
        Intent intent = new Intent(this,clazz);
        if (bundle!=null)
            intent.putExtras(bundle);
        startActivity(intent);
    }
    public void startPage(Class clazz){
        startPage(null,clazz);
    }
    protected <T extends View> T f(int id){
        return findViewById(id);
    }
}
